package com.amar.dtadmin.apidoc.util;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationGroupManager;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.AnAction;

import java.util.Arrays;
import java.util.function.Function;

/**
 * @author xiaoshiqiang
 * @since 2025/2/8
 */
public class NotificationUtils {
    public static final NotificationGroup DEFAULT_GROUP = NotificationGroupManager.getInstance().getNotificationGroup("DtAdminApiDocGroup");

    public static void notifyInfo(String content) {
        Notification notification = DEFAULT_GROUP.createNotification(content, NotificationType.INFORMATION);
        Notifications.Bus.notify(notification);
    }

    public static void notifyInfo(String title, String content) {
        Notification notification = DEFAULT_GROUP.createNotification(content, NotificationType.INFORMATION).setTitle(title);
        Notifications.Bus.notify(notification);
    }

    public static void notifyWarning(String content) {
        Notification notification = DEFAULT_GROUP.createNotification(content, NotificationType.WARNING);
        Notifications.Bus.notify(notification);
    }

    public static void notifyWarning(String title, String content) {
        Notification notification = DEFAULT_GROUP.createNotification(content, NotificationType.WARNING).setTitle(title);
        Notifications.Bus.notify(notification);

    }

    public static void notifyError(String content) {
        Notification notification = DEFAULT_GROUP.createNotification(content, NotificationType.ERROR);
        Notifications.Bus.notify(notification);
    }

    public static void notifyError(String title, String content) {
        Notification notification = DEFAULT_GROUP.createNotification(content, NotificationType.ERROR).setTitle(title);
        Notifications.Bus.notify(notification);
    }

    public static void notifyWithAction(NotificationType type, String title, String content, AnAction... actions) {
        Notification notification = DEFAULT_GROUP.createNotification(title, content, type);
        if (actions != null) {
            Arrays.stream(actions).forEach(notification::addAction);
        }
        Notifications.Bus.notify(notification);
    }

    public static void notifyWithAction(NotificationType type, String title, String content, Function<Notification, AnAction> action) {
        Notification notification = DEFAULT_GROUP.createNotification(title, content, type);
        if (action != null) {
            notification.addAction(action.apply(notification));
        }
        Notifications.Bus.notify(notification);
    }
}
